<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>教师课表</title>

<link rel="stylesheet" href="/Schedule/css/teacherTab.css">

<script src="/Schedule/js/jquery.min.js"></script>
<link rel="stylesheet" href="/Schedule/css/bootstrap.min.css">
<link rel="stylesheet" href="/Schedule/css/bootstrap-theme.min.css">
<script src="/Schedule/js/bootstrap.min.js"></script>


<script type="text/javascript">
	function getTeachers(textView) {
		var teacher_name = textView.value;
		$("#teacherSelect").empty();
		var xmlhttp;
		if (window.XMLHttpRequest) {
			// code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp = new XMLHttpRequest();
		} else {// code for IE6, IE5
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		xmlhttp.onreadystatechange=function()
		  {
		  if (xmlhttp.readyState==4 && xmlhttp.status==200)
		    {
		   		var select = document.getElementById("teacherSelect");
		   		select.innerHTML = ""
		   		var teachers = $.parseJSON(xmlhttp.responseText);
		   		for(var i = 0; i < teachers.length; i++) {
					select.options.add(new Option(teachers[i].teacher_name,teachers[i].teacher_id));
				} 
		    }
		  }
		xmlhttp.open("GET","/Schedule/json/teacher/list?teacher_name=" + teacher_name ,true);
		xmlhttp.send();
	}
	//
	function getSchedule() {
		var Sel_XNXQ = $('#termSelect option:selected') .val();
		var Sel_JS = $('#teacherSelect option:selected') .val()
		if (typeof(Sel_JS) == "undefined" || Sel_JS == "") {
			alert("请选择需要查询的老师！")
			return;
		}
		var type = $('input:radio[name="type"]:checked').val();
		var txt_yzm = $("#verCode").val();
		$("#verCode").val("");
		$("#teacherSchedule").html("");
		$("#picLoading").show();
		$("#picGif").hide();
		var xmlhttp;
		if (window.XMLHttpRequest) {
			// code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp = new XMLHttpRequest();
		} else {// code for IE6, IE5
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		xmlhttp.onreadystatechange=function() {
		  if (xmlhttp.readyState==4 && xmlhttp.status==200) {
			    $("#picLoading").hide();
			  	var div = document.getElementById("teacherSchedule");
		   		var table = $.parseJSON(xmlhttp.responseText);
			  	if (table.schedule_content == "null") {
			  		if ($("#match").is(':hidden')) {
			  			$("#match").show();
					}else{
						alert("请输入验证码！")
					}
			  		  
				}else if(table.schedule_content == "txt_yzm"){
					refleshValidate(document.getElementById("imgVerCode"));
					alert("验证码错误！");
				}else{
					div.innerHTML = table.schedule_content;
					 $("#match").hide();
					 $("#picGif").hide();
				}
		   		
		    }
		  }
		xmlhttp.open("POST","/Schedule/json/teacher/course" ,true);
		xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
		xmlhttp.send("Sel_XNXQ=" + Sel_XNXQ + "&Sel_JS=" + Sel_JS + "&type=" + type + "&txt_yzm=" + txt_yzm);
	}
	
	function refleshValidate(image){
		image.src="/Schedule/json/teacher/validate?t="+new Date().getMilliseconds();
	}
	
	
</script>

</head>
<body style="width: 900px; margin: 0 auto">
	<div>
		<img src="/Schedule/css/top.png" width="100%">
	</div>

	<div>
		<div class="txtTeacherTab">教师课表</div>
		<div>
			<HR
				style="FILTER: alpha(opacity = 100, finishopacity = 0, style = 3)"
				width="94%" color=#AAAAAA SIZE=2 />
		</div>
	</div>

	<div>
		<div class="txtSemester" style="margin-top: 20px">
			学年学期 <select id="termSelect" name="Sel_XNXQ"
				style="width: 200px; height: 25px; margin-left: 4px; margin-right: 65px">
				<c:forEach items="${terms}" var="p">
					<option value="${p.term_id}">${p.term_name}</option>
				</c:forEach>
			</select> 教&nbsp;&nbsp;&nbsp;师 
			<input type="text" onchange="getTeachers(this)" style="width: 100px; height: 25px; margin-left: 4px"> 
				<select name="Sel_JS" id="teacherSelect" style="width: 180px; height: 25px">
				<c:forEach items="${teachers}" var="p">
					<option value="${p.teacher_id}">${p.teacher_name}</option>
				</c:forEach>
			</select> 
			<input type="button" onclick="getSchedule()" class="btn-primary" value="  检     索  " />
		</div>
	</div>
	<div style="margin-top: 20px; margin-left: 50px; font-size: 15px;">
		<div style="float: left;">
			<input type="radio" name="type" value="1" checked="checked">格式一
			<input type="radio" name="type" value="2" style="margin-left: 80px">格式二
		</div>
		<div id="match"  style="margin-right: 180px; float: right; display:none; ">
			 验证码
			<input id="verCode" name="txt_yzm" type="text" style="width: 100px; height: 25px; margin-left: 4px">
			<img id="imgVerCode" onclick="refleshValidate(this)" alt="单击刷新！" src="/Schedule/json/teacher/validate" style="height: 25px; width: 180px">
		</div>
		<div style="clear: both;"></div>
	</div>

	<div id="teacherSchedule" style="margin-top: 20px; width: 100%;"></div>
	<div id="picGif"
		style="width: 80%; margin: 0 auto; margin-top: 20px; margin-bottom: 20px">
		<img src="/Schedule/css/dongtu.gif">
	</div>
	<div id="picLoading"
		style="width: 60%; margin: 0 auto; margin-top: 20px; margin-bottom: 20px; display: none;">
		<img src="/Schedule/css/loading.gif">
	</div>
</body>
</html>